package com.itheima.case2.web;


import com.fasterxml.jackson.databind.ser.Serializers;
import com.itheima.case2.pojo.Role;
import com.itheima.case2.service.RoleService;
import com.itheima.case2.utils.BaseController;
import com.itheima.case2.utils.BeansFactory;
import com.itheima.case2.vo.Result;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/role")
public class RoleServlet extends BaseServlet {


     public void findAllRoles(HttpServletRequest request, HttpServletResponse response) {

          RoleService roleService= BeansFactory.getSingleBean("roleService");
           List<Role> roleList=roleService.findAllRoles();

          try {
              BaseController.printResult(response,new Result(true,"查询成功",roleList));
          } catch (IOException e) {
              e.printStackTrace();
              try {
                  BaseController.printResult(response,new Result(false,"查询失败"));
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }


      }


}
